//
//  ZBFileUntil.m
//  ZBOpenGLESDemo
//
//  Created by apple on 2018/7/17.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZBFileUntil.h"
#import <sys/stat.h>

// 获取文件路径
const char *zb_pathForResource(const char *fileName)
{
    NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:fileName] ofType:nil];
    return [path fileSystemRepresentation];
}

// 读取文件数据
char *zb_ReadFile(const char *fileName)
{
    struct stat statbuf;  //文件信息
    
    char *source;
    
    FILE *fp; /*定义一个文件指针*/
    
    /*打开当前目录名为wenjian的文件只读*/
     fp = fopen(fileName, "r");
    if(fp == NULL){
        /*提示打开不成功*/
        return 0;
    }
    
    stat(fileName, &statbuf);
    
    source = (char *) malloc(statbuf.st_size + 1);
    
    fread(source, statbuf.st_size, 1, fp);
    
    source[statbuf.st_size] = '\0';
    
    fclose(fp);
    
    return source;
}


long long zb_fileSizeAtPath(NSString*filePath){
    
    struct stat st;
    if(lstat([filePath cStringUsingEncoding:NSUTF8StringEncoding], &st) == 0){
        return st.st_size;
    }
    return 0;
}

